#include <iostream>
#include "Poker.h"
#include "PokerData.h"
#include "CardTypeData.h"
#include "CardTypeManager.h"
#include <algorithm>
#include "HandPokerRateTable.h"

using namespace std;

vector<Poker> shufflePoker() {
  vector<Poker> list;
  for (int value = TWO; value <= ACE; value++) {
    for (int suit = DIAMOND; suit <= SPADE; suit++) {
      list.push_back(Poker((Value)value, (Suit)suit));
    }
  }
  srand(static_cast<unsigned int>(time(0)));
  random_shuffle(list.begin(), list.end());
  return list;
}

int main(int c, char ** param) {

  vector<Poker> pokers = shufflePoker();

  HandPoker handPoker1(pokers.at(0), pokers.at(1));
  HandPoker handPoker2(pokers.at(2), pokers.at(3));

  const Poker * poker = handPoker1.getHandPoker();
  for (int i = 0; i < HAND_POKER_COUNT; i++) {
    cout << "player one value:" << poker[i].value << " suit:" << poker[i].suit << endl;
  }

  cout << "player one win Rate:" << HandPokerRateTable::sharedHandPokerRateTable()->getHandPokerRate(handPoker1) << endl;

  poker = handPoker2.getHandPoker();
  for (int i = 0; i < HAND_POKER_COUNT; i++) {
    cout << "player two value:" << poker[i].value << " suit:" << poker[i].suit << endl;
  }
  cout << "player two win Rate:" << HandPokerRateTable::sharedHandPokerRateTable()->getHandPokerRate(handPoker2) << endl;

  FlopPoker flopPoker(pokers.at(4), pokers.at(5), pokers.at(6));
  
  poker = flopPoker.getFlopPoker();
  for (int i = 0; i < FLOP_POKER_COUNT; i++) {
    cout << "flop value:" << poker[i].value << " suit:" << poker[i].suit << endl;
  }

  TurnPoker turnPoker(pokers.at(7));
  cout << "trun value:" << turnPoker.getTurnPoker()->value << " suit:" << turnPoker.getTurnPoker()->suit << endl;

  RiverPoker riverPoker(pokers.at(8));
  cout << "River value:" << riverPoker.getRiverPoker()->value << " suit:" << riverPoker.getRiverPoker()->suit << endl;

  PokerData pokerData1;
  pokerData1.setHandPoker(handPoker1);
  pokerData1.setFlopPoker(flopPoker);
  pokerData1.setTurnPoker(turnPoker);
  pokerData1.setRiverPoker(riverPoker);

  PokerData pokerData2;
  pokerData2.setHandPoker(handPoker2);
  pokerData2.setFlopPoker(flopPoker);
  pokerData2.setTurnPoker(turnPoker);
  pokerData2.setRiverPoker(riverPoker);

  CardTypeData cardTypeData1 = CardTypeManager::sharedCardTypeManager()->getCardTypeData(pokerData1);
  cout << "player one cardType:" << cardTypeData1.type  << " " << cardTypeData1.first << " " << cardTypeData1.second << " "
        << cardTypeData1.third << " " << cardTypeData1.fourth << " " << cardTypeData1.fifth << endl; 

  CardTypeData cardTypeData2 = CardTypeManager::sharedCardTypeManager()->getCardTypeData(pokerData2);
  cout << "player two cardType:" << cardTypeData2.type  << " " << cardTypeData2.first << " " << cardTypeData2.second << " "
        << cardTypeData2.third << " " << cardTypeData2.fourth << " " << cardTypeData2.fifth << endl; 

  if (cardTypeData1 == cardTypeData2) {
    cout << "Player one tie Player two" << endl;
  } else if (cardTypeData1 < cardTypeData2) {
    cout << "Player two win" << endl;
  } else {
    cout << "Player one win" << endl;
  }
  return 0;
}
